package com.heu.blood.autologous.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.heu.blood.application.exception.ApplicationExceptionEnum;
import com.heu.blood.autologous.entity.BloodInformationAutologousEntity;
import com.heu.blood.autologous.vo.BloodInventoryAutologousSelectVo;
import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.globalExceptionHandler.MyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.heu.blood.autologous.entity.BloodInventoryAutologousEntity;
import com.heu.blood.autologous.service.BloodInventoryAutologousService;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;



/**
 * 
 *
 * @author lyj
 * @email lyj@heu.com
 * @date 2025-03-15 16:23:25
 */
@RestController
@RequestMapping("autologous/bloodinventoryautologous")
public class BloodInventoryAutologousController {
    @Autowired
    private BloodInventoryAutologousService bloodInventoryAutologousService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ControllerLogAnnotation(module = "自体血模块", operate = "分页查询血液库存信息")
    public R list(@RequestBody BloodInventoryAutologousSelectVo bloodInventoryAutologousSelectVo){
        PageUtils page = bloodInventoryAutologousService.queryPage(bloodInventoryAutologousSelectVo);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		BloodInventoryAutologousEntity bloodInventoryAutologous = bloodInventoryAutologousService.getById(id);

        return R.ok().put("bloodInventoryAutologous", bloodInventoryAutologous);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BloodInventoryAutologousEntity bloodInventoryAutologous){
		bloodInventoryAutologousService.save(bloodInventoryAutologous);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BloodInventoryAutologousEntity bloodInventoryAutologous){
		bloodInventoryAutologousService.updateById(bloodInventoryAutologous);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		bloodInventoryAutologousService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    @RequestMapping("getUnreceivedBloodByApplicationId")
    @ControllerLogAnnotation(module = "自体血模块", operate = "根据申请单id查询未签收的库存血液信息")
    public R getUnreceivedBloodByApplicationId(String applicationId){
        List<BloodInventoryAutologousEntity> res = bloodInventoryAutologousService.getUnreceivedBloodByApplicationId(applicationId);
        return R.ok().put("data", res);
    }


    /**
     * 回显库存信息
     * @param bloodIds
     * @return
     */
    @RequestMapping("echoInventoryInfo")
    @ControllerLogAnnotation(module = "自体血模块", operate = "回显库存信息")
    public R echoInventoryInfo(@RequestBody List<String> bloodIds){
        List<BloodInventoryAutologousEntity> res = bloodInventoryAutologousService.echoInventoryInfo(bloodIds);
        return R.ok().put("data", res);
    }


    /**
     * 补全信息后签收并插入到血液信息表
     * @param bloodInformationAutologousEntities
     * @return
     */

    @RequestMapping("confirmBloodReceipt")
    @ControllerLogAnnotation(module = "自体血模块", operate = "补全信息后签收并插入到血液信息表")
    public R confirmBloodReceipt(@RequestBody List<BloodInformationAutologousEntity> bloodInformationAutologousEntities){
        int result= bloodInventoryAutologousService.confirmBloodReceipt(bloodInformationAutologousEntities);
        return R.ok();
    }

}
